package Dao.impl;

import Dao.BaseDao;
import Dao.MusicMngDao;
import pojo.Songs;

import java.util.List;

/**
 * 作者：杨晋
 */
public class MusicMngDaoImpl extends BaseDao<Songs> implements MusicMngDao {
    /**
     * 获取歌曲列表
     * @param startIndex
     * @param targetTotal
     * @return
     */
    public List<Songs> getSongList(Integer startIndex, Integer targetTotal){
        String sql = "SELECT * FROM songs LIMIT ?, ?";
        List<Songs> songsList = getBeanList(sql, startIndex, targetTotal);
        return songsList;

    }

    public List<Songs> selectSongList(){
        String sql = "SELECT * FROM songs";
        List<Songs> songsList = getBeanList(sql);
        return songsList;
    }

    @Override
    public List<Songs> selectUserListByName(String songName) {
        //        昵称模糊查询
        String sql = "SELECT * FROM songs WHERE title like concat('%', ?, '%')";
        List<Songs> userList = getBeanList(sql, songName);
        return userList;
    }


    @Override
    public Songs getSongById(int songId) {
        String sql = "SELECT * FROM songs WHERE songId =?";
        return getBean(sql, songId);
    }

    @Override
    public boolean updateSong(Songs songs) {
        String sql = "UPDATE songs SET title=?, description =?,uploaderId =?, categoryId =? WHERE songId =?";
        int result = update(sql, songs.getTitle(), songs.getDescription(), songs.getUploaderId(), songs.getCategoryId(), songs.getSongId());
        return result > 0;
    }

    @Override
    public boolean deleteUploadedSong(int songId) {
        String sql = "DELETE FROM songs WHERE songId = ?";
        int result = update(sql, songId);
        return result > 0;
    }

}